import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from "vuex-persistedstate";

Vue.use(Vuex)

export default new Vuex.Store({
    plugins: [createPersistedState()],
    state: {
        user: null
    },
    mutations: {
        login(state, v) {
            state.user = v;
        },
        logout(state) {
            state.user = null;
        }
    },
    actions: {
        login(context, v) {
            context.commit("login", v);
        },
        logout(context) {
            context.commit("logout");
        }
    },
    modules: {},
    getters: {
        hasLogin(state) {
            return state.user != null;
        }
    }
})
